package com.shopmall.common.rabbitmq;

import com.alibaba.fastjson.JSON;
import com.shopmall.goods.entity.GoodsInfo;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

@Service
@RabbitListener(queues = "76-queues")
public class DirectReceiver {
    @RabbitHandler
    public void process(String msg){
        try{
            //接收消息
            GoodsInfo goodsInfo = JSON.parseObject(msg, GoodsInfo.class);
            if(goodsInfo!=null && "1".equals(goodsInfo.getStatus())){
                //把数据添加到es中
            }
            if(goodsInfo!=null && "0".equals(goodsInfo.getStatus())){
                //要根据ID将数据从es中删除
            }
            System.out.println(msg);
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
